<script type="text/javascript">
	$(document).ready(function(){
		//$("#test").click(function () {
		


		$("#test").click(function(){
			var val = [];
			$(':checkbox:checked').each(function(i){
			  val[i] = $(this).val();
			  alert(val[i]);
			});

		});
		
		
	});
	function printCheque(id){
		var task = "printCheque";
		var company_name = $("#company_name").val();
		var sum = $("#sum").val();
		
		var val = [];
		var count=0;
		
		$(':checkbox:checked').each(function(i){
		  val[i] = $(this).val();
		  count++;
		  //alert(val[i]);
		});

		if (count == 0) {
			alert ("กรุณาเลือกฎีกาที่ต้องการพิมพ์ด้วยครับ");
		} else {
			$('<div>').dialog2({
				autoOpen: true,
				title: "พิมพ์เช็ค",
				content: "dlgPrintCheque.php?sum=" + sum + "&company_name=" + company_name + "&val=" + val,
				id: "modal-printCheque"
			});
		}
	}
</script>

<?php
	include("includes/connect.php");
	include("includes/function.php");

	$db = new myDBS;

	$company_name = $_REQUEST["company_name"];

	$sql ="SELECT tbl_petition.*, pp_check_job.proID, projectName, amount, instalment FROM tbl_petition, pp_check_job WHERE tbl_petition.ppID = pp_check_job.ppID and approved_status = 'Approved' and company_name = '$company_name' and cheque_no is null Order by approved_date asc";
	$result = $db->runSQL($sql);
?>
	
	<table id="petition" class="table table-striped" width="100%" >
		<caption><br></caption>
		<thead>
			<tr>
				<th>#</th>
				<th>เลขที่ฎีกา</th>
				<th>เลขที่โครงการ</th>
				<th>ชื่อโครงการ</th>
				<th>งบประมาณ</th>
				<th>ยอดเบิกจ่าย</th>
				<th>งวดที่</th>
				<th>วันที่เบิกฏีกา</th>
				<th>รายละเอียดเพิ่มเติม</th>
				<th>เลือก</th>

			</tr>
		</thead>
		<tbody>
			<?php
				$i=0;
				$sum=0;
				while ( $rows = $db->fetch_object ( $result )){
					$i++;
					$sum=$sum + $rows->inpNet;

			?>
			<tr>
				<td><?php echo $i; ?></td>
				<td><?php echo $rows->p_id; ?></td>
				<td>
				<?php 
						if($rows->veri_status == "Not Verify") {
				?>
				<a href="index.php?pages=sumPetition1&petition_id=<?php echo $rows->petition_id; ?>" target="_blank"><?php echo $rows->proID; ?></a>
				<?php
						} else {
							echo $rows->proID;
						}
				?>
					
				</td>
				
				<td><?php echo $rows->projectName; ?></td>
				<td><?php echo number_format($rows->amount,2); ?></td>
				<td><?php echo number_format($rows->inpNet,2); ?></td>
				<td><?php echo $rows->instalment; ?></td>
				<td><?php echo $rows->date_create; ?></td>
				<td>
					<a href="#" id="info_<?php echo $rows->ppID; ?>"><i class="icon-info-sign"></i>&nbsp;ดู</a>
				</td>
				<td>
					<input type="checkbox" name="check[]" id="check_<?php echo $rows->petition_id; ?>" value="<?php echo $rows->petition_id; ?>" />
				</td>
	 			
				
			</tr>
			<?php
					
				}
			?>
			<tr>
				<td colspan="5">รวมทั้งหมด</td>
				<td colspan="4"><?php echo number_format($sum,2); ?><input type="hidden" name="sum" id="sum" value="<?php echo $sum; ?>"></td>
			</tr>
		</tbody>


	</table>
	<a href="javascript:printCheque()" role="button" class="btn btn-large btn-primary" target="_blank"><i class="icon-print icon-white"></i> พิมพ์เช็ค</a>
	<a id="test" role="button" class="btn btn-large btn-primary"><i class="icon-print icon-white"></i> test</a>
